﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NUnit.Framework;
using AL100.BankApplication.BLL;

namespace AL100.BankApplication.Tests
{
    [TestFixture]
    class Test_Visitors
    {
        public void Test_TenEurosVisitor()
        {
            Bank bank = Bank.Instance();

            // Creates 10 accounts with 100 € each..
            for (int i = 0; i < 10; i++)
            {
                bank.CreateAccount("Nom" + i, "Prénom" + i, 100);
            }

            // Creates the Visitor object that will withdraw 10 € on each 
            // account of the Bank.
            IVisitor visitor = new TenEurosVisitor();

            // Makes the visitor do its job on the Bank.. (on the
            // bank's accounts in fact)..
            bank.Accept(visitor);

            // Let's get the sum of all money in the Bank (supposingly 900 now)..
            // with LINQ..
            var query = (from account in bank.Accounts
                         select account.Balance).Sum();

            
            Assert.AreEqual(query, 900); 
        }
    }
}
